﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Principal;
using EnCor.ObjectBuilder;

namespace EnCor.Security
{
    [AssembleConfig(typeof(WindowsAuthenticationAdapterConfig))]
    public class WindowsAuthenticationAdapter : AuthenticationAdapter
    {
        #region ICredentialAdapter Members

        /// <summary>
        /// Get WindowsCredential of current enviroment context.
        /// </summary>
        /// <returns></returns>
        public override Credential GetCredential()
        {
            WindowsIdentity identity = WindowsIdentity.GetCurrent();
            if (identity != null)
            {
                return new WindowsCredential(identity);
            }
            return null;
        }

        #endregion

        #region IAuthenticationAdapter Members

        /// <summary>
        /// Will do nothing, since the it is a readonly adapter.
        /// </summary>
        /// <param name="token"></param>
        public override void SetCredential(AuthenticateToken token)
        {
            
        }

        /// <summary>
        /// Will do nothing, since the it is a readonly adapter.
        /// </summary>
        public override void ClearCredential()
        {
            
        }

        #endregion
    }
}
